<?php
/*  
  Copyright (c) 2010-02 SongCMS 
  SongCMS All Rights Reserved. 
  Support:www.SongCMS.com
  QQ:544255858   19951025
  Author:Song  Version:3.17
  Date:2010-08-12 09:28:32
*/
include_once('Admin.php');
if ($_POST['Action']=='Add'){
	$JurisdiCtion = $_POST['JurisdiCtion']; 
	if ($JurisdiCtion != '') {$JurisdiCtion = implode(",",$JurisdiCtion);}
	$Count = $db->SelectSQL("SELECT COUNT(`ID`) FROM `" . $dbprefix . "admin` WHERE `UserName` = '" . $_POST['UserName'] . "'");
	$Count = $Count[0][0];
	if ($Count != 0){AdminLog(2,1,'添加用户名为"' . $_POST['UserName'] . '"的管理员失败，原因：添加的管理员已经存在！'); MsgBox (1,'该管理员已经存在！','-1');}
	$SQL = "INSERT INTO `" . $dbprefix . "admin` (`UserName`,`PassWord`,`LastLoginIP`,`LastLoginTime`,`JurisdiCtion`,`Levels`) ";
	$SQL .= "VALUES ('" . $_POST['UserName'] . "','" . md5($_POST['PassWord']) . "','" . $_SERVER['REMOTE_ADDR'] . "',NOW(),'" . $JurisdiCtion . "', " . $_POST['levels'] . ");";
	if($db->ExecuteSQL($SQL)){
		AdminLog(2,1,'添加用户名为"' . $_POST['UserName'] . '"的管理员，结果：操作成功！');
		MsgBox (1,'管理员添加成功！','AdminManage.php');
	} else {
		AdminLog(2,1,'添加用户名为"' . $_POST['UserName'] . '"的管理员，结果：操作失败！');
		MsgBox (1,'管理员添加失败！','0');	
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="./images/adminstyle.css" rel="stylesheet" type="text/css" />
<link rel="Shortcut Icon" href="../favicon.ico">
<link rel="Bookmark" href="../favicon.ico">
<script type="text/javascript">
var flag = true;
function selall(obname){ //全选/取消
  	var e = document.getElementsByName(obname);
	for (var i=0;i<e.length;i++){
     	e[i].checked  = flag;
   	}
	flag = !flag;
} 
function check(State){ 
	if (State == 0) {
		document.getElementById("Super").style.display = "block";
	} else {
		document.getElementById("Super").style.display = "none";
	}
}
function nCheck() {
	if(document.form1.UserName.value.length<5){
		alert('用户名不得少于5个字符。') ;
		document.form1.UserName.focus();
		return false;		
	}
	if(document.form1.PassWord.value.length<5){
		alert('用户密码不得少于5个字符。') ;
		document.form1.PassWord.focus();
		return false;		
	}
	if(document.form1.PassWord.value != document.form1.PassWord2.value){
		alert('两次输入的密码不一致。') ;
		document.form1.PassWord2.focus();
		return false;		
	}
}
</script>
<script src="../js/csshovernotie6.js" type="text/javascript"></script>
</head>
<body>
<br />
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr class="Notodd"><td>&nbsp;</td>
	<td align="right"><input type="button" value="管理员管理" onClick="javascript:location.href='AdminManage.php?Lang=<?php echo $Lang?>'"></td>
	</tr>
</table>
<table width="98%" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#CCCCCC">
  <form id="form1" name="form1" method="post" action="AdminAdd.php" onSubmit="return nCheck()">
  <tr class="odd">
    <td colspan="3" align="center" class="Main_Title">添加后台管理员</td>
  </tr>
  <tr class="odd">
    <td align="right">权限级别：</td>
    <td>
    <input name="levels" type="radio" value="0" checked onClick="return check(0)" />普通管理员
    <input name="levels" type="radio" value="1" onClick="return check(1)" />超级管理员
    </td>
    <td>普通管理员：无权对其他管理员进行管理，管理权限可单独设定；</td>
  </tr>
  <tr class="odd">
    <td align="right">用 户 名：</td>
    <td><input name="UserName" type="text" id="UserName" maxlength="20" class="input2" />
      <span class="red">*</span></td>
    <td>5-20个字符组成</td>
  </tr>
  <tr class="odd">
    <td align="right">密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码：</td>
    <td><input name="PassWord" type="password" class="input2" id="PassWord" maxlength="20" />
      <span class="red">*</span></td>
    <td>5-20个字符组成</td>
  </tr>
  <tr class="odd">
    <td align="right">确认密码：</td>
    <td><input name="PassWord2" type="password" id="PassWord2" maxlength="20" class="input2" />
      <span class="red">*</span></td>
    <td>5-20个字符组成</td>
  </tr>
  <tr id="Super" class="odd">
    <td align="right">管理权限：</td>
<td>
<input name="chkAll" type="checkbox" id="chkAll" onClick="selall('JurisdiCtion[]')" value="checkbox"><font color="#0000FF">全部选中/全部取消</font><br />
<?php
$n = 0;
foreach ($xSystem as $x => $m){
	if($m[0] == 1 && $m[6] == 1){
		$AdminPage[] = $m;
	}
}
echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">' . "\n";
echo '<tr>' . "\n";
foreach ($AdminPage as $i => $p){
	echo '<td>';
	if ($p[2] != 'AdminAdd.php' && $p[2] != 'AdminManage.php'){ 
		echo '<input name="JurisdiCtion[]" type="checkbox" id="JurisdiCtion[]" value="' . $p[2] . '" />' . $p[3] . "\n";
	} else {
		echo '<input disabled type="checkbox" />' . $p[3] . "\n";
	}
	echo '</td>';
	if((($n++)+1)%3==0){echo '</tr><tr>';}
}
echo '</tr></table>' . "\n";
?>
</td>
    <td>该项只对普通管理员有效，超级管理员没有限制；</td>
  </tr>
  <tr class="odd">
    <td><input name="Action" type="hidden" id="Action" value="Add" /></td>
    <td><input type="submit" name="button" id="button" value="提 交" class="submit" />
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input type="reset" name="button2" id="button2" value="重 置" class="submit" /></td>
    <td>&nbsp;</td>
  </tr>
</form>
</table>
</body>
</html>